import {BannerItem,ApiRes,GoodItem,HomeGoods,Brand,HomeProduct,Special} from '@/types/data'
import request from '@/utils/request'
import {defineStore} from 'pinia'
export default defineStore('home',{
    state() {
        return {
            bannerList:[] as BannerItem[],
            newGoodList: [] as GoodItem[],
            hotGoodList:[] as HomeGoods[],
            brandList: [] as Brand[],
            productList: [] as HomeProduct[],
            specialList: [] as Special[]
        }
    },
    actions:{
        async getBannerList () {
            const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
            // console.log(res.data.result)
            this.bannerList = res.data.result
            
        },
        async getnewList () {
            const {data} = await request.get<ApiRes<GoodItem[]>>('/home/new')
            this.newGoodList = data.result
            // console.log(data)
            
        },
        async getHotList () {
            const {data} = await request.get<ApiRes<HomeGoods[]>>('/home/hot')
            this.hotGoodList = data.result
            // console.log(res)
            
        },
        async getBrandList() {
            const res = await request.get<ApiRes<Brand[]>>('/home/brand')
            // console.log(res)
            this.brandList = res.data.result
        },
        async getProductList() {
            const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
            this.productList = res.data.result
        },
        async getSpecialList() {
            const res = await request.get<ApiRes<Special[]>>('/home/special')
            this.specialList = res.data.result
        }
    }
})